package com.cp.admin.modular.system.controller;

import com.cp.core.base.controller.BaseController;
import com.cp.admin.core.log.LogObjectHolder;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestParam;
import com.cp.admin.modular.system.model.SysConfig;
import com.cp.admin.modular.system.service.ISysConfigService;

/**
 * 系统配置表控制器
 *
 * @author fengshuonan
 * @Date 2018-04-06 09:32:47
 */
@Controller
@RequestMapping("/sysConfig")
public class SysConfigController extends BaseController {

    private String PREFIX = "/system/sysConfig/";

    @Autowired
    private ISysConfigService sysConfigService;

    /**
     * 跳转到系统配置表首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "sysConfig.html";
    }

    /**
     * 跳转到添加系统配置表
     */
    @RequestMapping("/sysConfig_add")
    public String sysConfigAdd() {
        return PREFIX + "sysConfig_add.html";
    }

    /**
     * 跳转到修改系统配置表
     */
    @RequestMapping("/sysConfig_update/{sysConfigId}")
    public String sysConfigUpdate(@PathVariable Integer sysConfigId, Model model) {
        SysConfig sysConfig = sysConfigService.selectById(sysConfigId);
        model.addAttribute("item",sysConfig);
        LogObjectHolder.me().set(sysConfig);
        return PREFIX + "sysConfig_edit.html";
    }

    /**
     * 获取系统配置表列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return sysConfigService.selectList(null);
    }

    /**
     * 新增系统配置表
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(SysConfig sysConfig) {
        sysConfigService.insert(sysConfig);
        return SUCCESS_TIP;
    }

    /**
     * 删除系统配置表
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer sysConfigId) {
        sysConfigService.deleteById(sysConfigId);
        return SUCCESS_TIP;
    }

    /**
     * 修改系统配置表
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(SysConfig sysConfig) {
        sysConfigService.updateById(sysConfig);
        return SUCCESS_TIP;
    }

    /**
     * 系统配置表详情
     */
    @RequestMapping(value = "/detail/{sysConfigId}")
    @ResponseBody
    public Object detail(@PathVariable("sysConfigId") Integer sysConfigId) {
        return sysConfigService.selectById(sysConfigId);
    }
}
